package com.miracle.android_voip_simple_demo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

/**
 * Created by pan on 2017/12/13.
 */

public class PrepareActivity extends Activity {
    private EditText et_render1_id, et_render2_id, et_render3_id;
    private Button btn_start;
    private String ip;
    private int port, mUserId;
    //将TYVoipAndroid 写成单例模式，建议使用一个管理类来管理

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_prepare);
        getValue();
        initView();
    }

    private void getValue() {
        Intent intent = getIntent();
        ip = intent.getStringExtra("ip");
        port = intent.getIntExtra("port",0);
        mUserId = intent.getIntExtra("userid",0);
    }

    private void initView() {
        et_render1_id = f(R.id.et_render1_id);
        et_render2_id = f(R.id.et_render2_id);
        et_render3_id = f(R.id.et_render3_id);
        btn_start = f(R.id.btn_start);
        //此处可选填入三个他人userId，对应选择对应三个Render显示框，可添加0~3名成员，0默认不添加
        //假设此时有两名成员处于登录状态，登入时填入Id分别为 1  、 2 ；
        //则需要分别填入对方userId，userId为1的填入2，userId为2的填入1，互相add对方节点，
        // 若只有一方添加另一方，则将会单方面接受对端数据；
        // 多人同理，依次类推；
        btn_start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(PrepareActivity.this, MeetingActivity.class);
                intent.putExtra("ip", ip);
                intent.putExtra("port", port);
                intent.putExtra("userid", mUserId);
                intent.putExtra("render1_id", Integer.valueOf(et_render1_id.getText().toString()));
                intent.putExtra("render2_id", Integer.valueOf(et_render2_id.getText().toString()));
                intent.putExtra("render3_id", Integer.valueOf(et_render3_id.getText().toString()));
                startActivity(intent);
            }
        });
    }

    private <T extends View> T f(int viewId) {
        return (T)findViewById(viewId);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}
